class_name UIManager
extends Node
# 当前UI
static var current_ui: Control
# 场景索引
static var next_index: int = 0
# 场景数组
static var scene_array : Array
# 主节点
static var main_node : CanvasLayer

# 初始化UI
static func init_ui(node: Node) -> void:
	main_node = node
	init_scene_array()
	load_next_ui()

# 加载下一个UI场景
static func load_next_ui() -> Node:
	# 如果有节点，则进行销毁
	if main_node.get_child_count() > 0 :
		current_ui.queue_free()
	# 获取下一个场景
	var scene_object = get_next_scene();
	print(scene_object.path)
	print(scene_object.name)
	# 加载场景
	var scene_ui:PackedScene = ResourceLoader.load(scene_object.path)
	# 场景实例化
	var scene_ui_inst = scene_ui.instantiate()
	# 设置场景名称
	scene_ui_inst.name = scene_object.name
	# 添加到子节点
	main_node.add_child(scene_ui_inst)
	# 修改当前场景
	current_ui = scene_ui_inst
	# 修改数据索引序号
	next_index += 1
	
	return current_ui

# 初始化所有需要按序加载的场景
static func init_scene_array() -> void:
	var scene_logo = {
		"name": "scene_logo",
		"path": "res://Scene/Logo/scene_logo.tscn"
	}
	var scene_load = {
		"name": "scene_load",
		"path": "res://Scene/Load/scene_load.tscn"
	}
	var scene_lobby = {
		"name": "scene_lobby",
		"path": "res://Scene/Lobby/scene_lobby.tscn"
	}
	var scenes = []
	scenes.append(scene_logo)
	scenes.append(scene_load)
	scenes.append(scene_lobby)
	
	scene_array = scenes

static func get_next_scene() -> Dictionary:
	return scene_array[next_index]
	
	
